home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / CustomWriterGX / ChooserPACK.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  3.9 KB  |  162 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         ChooserPACK.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for PACK resource used by the Chooser.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         10/04/95 - David Hayward -    Version 1.0.4 modified code so that
  14.                                     the driver can be build under MPW,
  15.                                     Metrowerks, and Symantec.  In general,
  16.                                     all that was required to do this was 
  17.                                     to add an inline-assembly jumptable
  18.                                     and to store all globals off of the
  19.                                     message manager instance context.
  20.                                     Also made a few changes so that the
  21.                                     driver can be rebuilt to support any
  22.                                     resolution by changing the #defines
  23.                                     kResolution and kPatStretch in
  24.                                     "CommonDefines.h"
  25.  
  26.         06/14/95 - Dave Hersey -    Version 1.0.3 to fix a bug in
  27.                                     CustomBufferingAndIO.c when creating
  28.                                     high-res PICTs, and to make the size
  29.                                     of buffers more flexible.
  30.  
  31.         05/26/95 - Dave Hersey -    Version 1.0.2 to add the new 'outp'
  32.                                     desktop printer resource in NewApp.c.
  33.  
  34.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  35.                                     CustomBufferingAndIO.c.
  36.  
  37.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  38.                                     ImageWriter driver.
  39.  
  40.     NOTE: Relevant goodies are listed in MPW's "Mark" menu.
  41. */
  42.  
  43.  
  44. #include <Types.h>
  45. #include <Traps.h>
  46. #include <Resources.h>
  47. #include <GXGraphics.h>
  48. #include <GXTypes.h>
  49. #include <GXPrinterDrivers.h>
  50. #include <GXPrinting.h>
  51. #include <Devices.h>
  52.  
  53.  
  54. // typedef for structure to hold globals for PACK code.
  55. typedef struct PACKglobal
  56. {
  57.     gxJob        job;
  58.     Str31        driverName;
  59. } PACKglobalRec, *PACKglobalPtr;
  60.  
  61.  
  62. // Prototype for main function.
  63. pascal OSErr PACKmain ( short message, short caller,
  64.                      StringPtr objName, StringPtr zoneName,
  65.                      ListHandle theList, long p2,
  66.                      PACKglobalPtr global) ;
  67.  
  68.  
  69. /*    -----------------------------------------------------------------------
  70.  
  71.     __Startup__ contains our jump table to the overrides.
  72.     This code must be kept in sync with the assembly code
  73.     in ChooserPACK.a
  74.  
  75.     -----------------------------------------------------------------------    */
  76.  
  77. #if defined(__MWERKS__)
  78.  
  79. #define kLeftButton            0x08000000
  80. #define kUsesOnAndOff        0x00100000
  81. #define kAcceptsInit        0x00020000
  82. #define kAcceptsTerminate    0x00000800
  83.  
  84. asm void __Startup__(void) ;
  85. asm void __Startup__(void)
  86. {
  87.     BRA.S    code            // branch to our actual code
  88.     DC.W    169                // device ID
  89.     DC.L    'PACK'            // device type
  90.     DC.W    0xF000            // master ID for resources (-4096)
  91.     DC.W    2                // version
  92.     DC.L    kLeftButton+kUsesOnAndOff+kAcceptsInit+kAcceptsTerminate
  93.  
  94. data:
  95.     ds.b    sizeof(PACKglobalRec)
  96.  
  97. code:
  98.     MOVE.L    (a7)+,a0        // move return address into a0
  99.     PEA        data            // add a pointer to our global data onto stack as last parameter
  100.     MOVE.L    a0,-(a7)        // put the return address back on the stack
  101.     jmp        PACKmain        // jump to it, so when it does the return, it goes to OUR caller
  102.     rts
  103. }
  104. #endif
  105.  
  106.  
  107. pascal OSErr PACKmain ( short message, short caller,
  108.                          StringPtr objName, StringPtr zoneName,
  109.                          ListHandle theList, long p2,
  110.                          PACKglobalPtr global)
  111. {
  112.     OSErr            anErr = noErr;
  113.  
  114.     // start up GX.
  115.     if (message == chooserInitMsg)
  116.     {
  117.         FCBPBRec    pb;
  118.  
  119.         // determine the driver name
  120.         pb.ioCompletion     = nil;
  121.         pb.ioNamePtr         = global->driverName;
  122.         pb.ioVRefNum         = 0;
  123.         pb.ioRefNum         = CurResFile();
  124.         pb.ioFCBIndx         = 0;
  125.         anErr = PBGetFCBInfo(&pb, false);
  126.  
  127.         global->job = nil;
  128.         if (anErr == noErr)
  129.         {
  130.             GXEnterGraphics();
  131.             anErr = GXGetGraphicsError(nil);
  132.             if (anErr == noErr)
  133.             {
  134.                 anErr = GXInitPrinting();
  135.                 if (anErr != noErr)
  136.                     GXExitGraphics();
  137.             }
  138.         }
  139.     }
  140.         
  141.     // Let the system handle the choosing for us.
  142.     if (anErr == noErr)
  143.     {
  144.         if ((global->job != nil) || (message == chooserInitMsg))
  145.         {
  146.             anErr = GXHandleChooserMessage(    &(global->job),
  147.                                             global->driverName,
  148.                                             message, caller, objName, zoneName, theList, p2);
  149.         
  150.             // Tear down GX when done.
  151.             if ((message == terminateMsg) && (p2 == terminateMsg))
  152.             {
  153.                 GXExitPrinting();
  154.                 GXExitGraphics();
  155.             }
  156.         }
  157.     }
  158.         
  159.     return anErr;
  160.  
  161. }
  162.